
import 'package:dotted_line/dotted_line.dart';
import 'package:flutter/material.dart';
import 'package:gw_github_flutter/common/route_name.dart';
import 'package:gw_github_flutter/generated/l10n.dart';
import 'package:gw_github_flutter/models/repo.dart';

class ToolsRoute extends StatefulWidget {
  ToolsRoute({Key? key}) : super(key: key);

  @override
  State<ToolsRoute> createState() => _ToolsRouteState();
}

class _ToolsRouteState extends State<ToolsRoute> {
  static const loadingTag = "##loading##"; //表尾标记
  // ignore: prefer_final_fields
  var _items = [
    Repo()
      ..name = RouteName.toolsRoute_imagePicker + " 图片和相机选择"
      ..route_path = RouteName.toolsRoute_imagePicker,
    
    Repo()..name = loadingTag
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(S.of(context).home),
      ),
      body: _buildBody(),
    );
  }

  Widget _buildBody() {
    return ListView.separated(
      itemCount: _items.length,
      itemBuilder: (context, index) {
        if (_items[index].name == loadingTag) {
          return Container(
            padding: const EdgeInsets.all(16.0),
            alignment: Alignment.center,
            child: const Text(
              "没有更多了",
              style: TextStyle(color: Colors.grey),
            ),
          );
        }
        return ListTile(
          title: Text(
            _items[index].name,
            style: TextStyle(fontSize: 13),
          ),
          subtitle: Text(_items[index].route_path ?? ""),
          onTap: () {
            Navigator.of(context).pushNamed(_items[index].route_path ?? "");
          },
        );
      },
      separatorBuilder: (context, index) {
        return const DottedLine(dashColor: Colors.red,);
      },
    );
  }
}